import requests
from lxml import etree

def certification():
    # 申请资质企业信息公开
    url = 'https://data.gdcic.net/Dop/Search/ApplyOpenList.aspx'
    headers = {
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36"
    }
    res = requests.get(url,headers=headers,verify=False)
    parser= etree.HTML(res.text)
    datas = parser.xpath("//*[@class='data-list']/tr")
    for data in datas[1:]:
        dict1 = {}
        name = data.xpath('./td/a')[0].text
        # print(name)
        type = data.xpath('./td[2]')[0].text.strip()
        # print(type)
        applications = data.xpath('./td[3]/div')
        # print(applications)
        sh = ""
        for application in applications:
            sh += "#"+application.xpath('.//text()')[0]
        # print(sh)
        monad = data.xpath('./td[4]')[0].text.strip()
        number = data.xpath('./td[5]')[0].text.strip()
        dict1["企业名称"] = name
        dict1["资质类别"] = type
        dict1["申请事项"] = sh
        dict1["受理单位"] = monad
        dict1["申请流水号"] = number
    

# 企业资质审查意见公示
url = 'https://data.gdcic.net/Dop/Search/ApplyPublicityList.aspx'
headers = {
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36"
    }
res = requests.get(url,headers=headers,verify=False)
parser= etree.HTML(res.text)
for data in datas[1:]:
    dict1 = {}
    name = data.xpath('./td/a')[0].text
    # print(name)
    type = data.xpath('./td[2]')[0].text.strip()
    # print(type)
    applications = data.xpath('./td[3]/div')
    # print(applications)
    sh = ""
    for application in applications:
        sh += "#"+application.xpath('.//text()')[0]
    # print(sh)
    monad = data.xpath('./td[4]')[0].text.strip()
    idea = data.xpath('./td[5]/div')[0].text.strip()
    number = data.xpath('./td[6]')[0].text.strip()
    t = data.xpath('./td[7]')[0].text
    dict1["企业名称"] = name
    dict1["资质类别"] = type
    dict1["申请事项"] = sh
    dict1["受理单位"] = monad
    dict1["审查意见"] = idea
    dict1["申请流水号"] = number
    dict1["公示截止日期"] = t
    print(dict1)
